﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>

    <style>
        .li_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
            float: left;
        }

        .ul_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="">
                    <div style="width: 80%; padding-top: 50px; padding-left: 50px">
                        <div style="padding: 20px;border: solid 0.5px;box-shadow: 0 0 5px 3px rgba(209, 209, 255, 0.5);border-radius: 10px">
                            <div>
                                <span style="font-size: 15px;font-weight: bold">注意事项：</span>
                                <br/>
                                <span style="font-size: 14px; line-height: 20px;padding-left: 20px">
                                    · 查询设备激活状况，可查询设备当前的绑定时间，以及上一次绑定时间、解绑时间和解绑方式；
								</span>
                                <br/>
                                <span style="font-size: 14px; line-height: 20px;padding-left: 20px">
                                    · 单个查询，输入设备IMEI/MEID号，点击确定按钮，即可查询；
								</span>
                                <br/>
                                <span style="font-size: 14px; line-height: 20px;padding-left: 20px">
                                    · 多个查询，选择的文件为excel文件（后缀为xls 或 xlsx），设备IMEI/MEID放到A列，1行1个，单次查询数量不能超过1000个；
								</span>
                            </div>
                            <br/>
                            <div>
                                <label style="float:left;padding-right: 10px">
                                    <input name="type" id="type" type="radio" value="0">
                                    <span class="lbl">单个查找: </span>
                                </label>
                                <input type="text" name="imei" id="imei" placeholder="输入IMEI/MEID">
                                <br/>
                            </div>
                            <br/>
                            <div>
                                <label style="float:left;padding-right: 10px;">
                                    <input name="type" id="type" type="radio" value="1">
                                    <span class="lbl">多个查找</span>
                                </label>
                                <input type="file" name="file" id="file" onchange="changeFile()">
                                <br/>
                            </div>
                            <br/>
                            <div style="height: 50px; font-size: 14px;color: red; ">
                                <span id="singleResult"
                                      style="display: block;float: left;margin-right: 10px;font-weight: bold"></span>
                                <span id="moreResult"
                                      style="display: none;float: left;margin-right: 10px;font-weight: bold"></span>
                                <input type="button" id="foundExcelUrl" value="下载文件" onclick="download(this)"
                                       style="display: none;float: left;background-color: #0c76cb;margin-right: 10px;color: white">
                            </div>
                        </div>
                        <div style="margin-top: 30px;margin-left: 100px">
                            <input class="btn btn-primary" type="button" onclick="save()" value="查找" id="submitBut">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());
</script>

<script type="text/javascript">
    //保存
    function save() {
        var formData = new FormData();
        var type = $("input[name='type']:checked").val();
        var imei = $("#imei").val();
        if (type == 0) {
            if (imei == "") {
                $("#imei").tips({
                    side: 3,
                    msg: '请输入imei号',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#imei").focus();
                return false;
            }
            formData.append("imei", imei);
        } else if (type == 1) {
            var fileObj = $('#file').get(0).files[0];
            if (!fileObj) {
                $("#file").tips({
                    side: 3,
                    msg: '请选择文件',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#file").focus();
                return false;
            }
            formData.append("file", fileObj);
            $("#moreResult").css("display", "block");
            $("#moreResult").text("正在进行查找，请耐心等待！");
        } else {
            $("#type").tips({
                side: 3,
                msg: '请选择查找类型',
                bg: '#AE81FF',
                time: 2
            });
            $("#type").focus();
            return false;
        }
        $("#submitBut").attr("disabled", true);
        formData.append("type", type);
        $.ajax({
            type: "post",
            url: "/device/searchActive",
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                $("#submitBut").attr("disabled", false);
                if (type == 0) {
                    $("#singleResult").css("display", "block");
                    $("#moreResult").css("display", "none");
                    $("#foundExcelUrl").css("display", "none");
                    if (data.code == 200) {
                        var msg = ""
                        $.each(data.data, function (n, value) {
                            msg += "<span style='font-weight: bolder'>" + value + "</span><br/><br/>"
                        })
                        $("#singleResult").html(msg);
                    } else {
                        $("#singleResult").text(data.msg);
                    }
                } else {
                    $("#singleResult").css("display", "none");
                    $("#moreResult").css("display", "block");
                    if (data.code == 200) {
                        $("#moreResult").text(data.data.msg);
                        if (data.data.fileName) {
                            $("#foundExcelUrl").css("display", "block");
                            $("#foundExcelUrl").attr("data-fileName", data.data.fileName);
                        }
                    } else {
                        $("#moreResult").text(data.msg);
                    }
                    $("#file").val("")
                }
            }
        })
    }

    function changeFile() {
        $("#foundExcelUrl").css("display", "none");
        $("#singleResult").css("display", "none");
        $("#moreResult").css("display", "none");
    }

    function download(obj) {
        var fileName = $(obj).attr("data-fileName");
        if (fileName) {
            window.location.href = "/device/downloadExcel?type=-1&fileName=" + fileName;
        }
    }
</script>
</body>
</html>
